(function($){
	// 逻辑组件
	$.fn.logicProducer = function(){
		function producer(){
		};
		producer.prototype = $.fn.logicProducer;
		var logic = new producer();
		return logic;
	};
	
	// 默认参数
	$.fn.logicProducer.defaults = {
	};
	
	// 下载需要的数据
	$.fn.logicProducer.load = function(options){
		var producer = this;
		this.data = $.extend({},producer.defaults,options);
		$.ajax({
			url: options.url,
			data: options.data,
			dataType: "json",
			type: "post",
			async:false,
			cache:false,
			success: function(data){
				LogicParams.data = data;
				producer.init();
				
			}
		});
	};
	
	// 显示逻辑
	$.fn.logicProducer.init = function(){
		var data = LogicParams.data;
		
		var logiclist = data.logiclist;
		var questionlist = data.questionlist;
		$(questionlist).each(function(index,question){
			if(index > 0) return;

			var component = $.fn.logicComponent(8);
			component.init();
			var logic = component.newLogic(8);
			component.show(logic);
			LogicTool.bindOneMasterClick(logic);
			LogicTool.bindDetailClick(logic);
			LogicTool.bindMasterClick(logic);
			LogicParams.logiclist.push(logic);
		});
		//alert($.toJSON(LogicParams.logiclist));
		if(questionlist.length == 0){ // 未创建问题
			$("#logicDIVNoQuestion").show();
		}else if(logiclist.length == 0){ //创建空逻辑提示
			//$("#logicDIVNo").show();
			$("#logicDIVSave").show();
			// 为点击绑定事件
			$("[id^=logicAdd_]").bind("click",function(evt){
				var type = $(this).attr("id").split("_")[1];
				LogicTool.hideOther();
				LogicTool.showLogicTypeList(type,type); //显示下拉
				evt.stopPropagation();
			});
			$(document).click(function(){
				LogicTool.hideOther();
			});
		}else{
			$("#logicDIVSave").show();
		}
	};
	
	// 创建逻辑
	$.fn.logicProducer.createLogic = function(seq){
		var component = $.fn.logicComponent(seq);
		component.init(data); // 问卷所有数据
		component.newLogic(); // 逻辑展示参数
		component.show(); // 显示逻辑
	}
	// 保存逻辑列表
	$.fn.logicProducer.setLogicArry = function (logic) {
		if (this.LogicArry == null) {
			this.LogicArry = new Array();
		}
		this.LogicArry.push(logic);
	};
	
	// 创建逻辑对象
	$.fn.logicProducer.newLogic = function(seq){
		
	};
})(jQuery);